<?php
namespace app\index\controller;

use app\index\model\Users as U;

use think\Controller;
use think\Db;
use think\Session;

class Users extends Base
{
    // ;public $return = new Users()

    public function index()
    {
        $id = session::get('uid');

        return $this->fetch();
    }

    /**
     * 用户-设置
     */
    public function setting()
    {
        return $this->fetch('users/setting/index');
    }

    /**
     * 个人设置
     */
    public function set_user()
    {
        // 获取用户信息
        if(input('post.')){
            $request = input('post.');
            $data = new U();
            $result = $data->edit_user($request);
            return $result;
        }else{
            $data = new U();
            $result = $data->getUserList();
            $this->assign("res",$result);
            return $this->fetch('users/setting/set_user');
        }
    }
    /**
     * 我的团队
     */
    public function team(){
        $data = new U();
        $result = $data->getUserList();
        $this->assign('res',$result);
        $team = $data->getSubordinate($result['user_id']);
        $this->assign('teams',$team);
        return $this->fetch();
    }
    /**
     * 用户-修改密码
     */
    public function edit_pwd()
    {
        if(input('post.')){

            $data = new U();
            $post = input('post.');
            $result = $data->edit_pwd($post);
            return $result;
        }else{   
            // 获取密保问题
            $encrypt = Db::name('encrypt')->select();
                $this->assign('encrypt',$encrypt);
            return $this->fetch('users/setting/edit_pwd');
        }
    }

    /**
     * 用户-注册会员
     */

    public function register_vip()
    {
        $data = new U();
        if(input('post.'))
        {
            $post = input('post.');
            $res = $data->add_register_vip($post);
            return $res;
        }else{
            $result = $data->getUserList();
            $this->assign('res',$result);
            return $this->fetch();

        }
    }

    /**
     * 用户查看下级
     */
    public function next_level()
    {
        $id = input('param.uid');
        $data = new U();
        $result = $data->next_level($id);
        $this->assign('result',$result);
        return $this->fetch();
    }
}
